package org.hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.Test;

/**
 * 访问HDFS系统示例
 */
public class Demo01AccessHDFS {
    @Test
    public void testAccessHdfs() throws Exception {
        System.setProperty("HADOOP_USER_NAME", "hadoop");
        System.setProperty("HADOOP_HOME", "D:/program/hadoop-3.2.2");
        System.setProperty("hadoop.home.dir", "D:/program/hadoop-3.2.2");
        Configuration config = new Configuration();
        config.set("fs.defaultFS", "hdfs://192.168.56.201:8020");
        FileSystem fs = FileSystem.get(config);
        FileStatus[] stas = fs.listStatus(new Path("/"));
        for (FileStatus f : stas) {
            System.out.println(f.getPermission().toString() + " " + f.getPath().toString());
        }
        fs.close();
    }
}
